import Vue from 'vue'
import EVue from 'evue'
import Clipboard from 'clipboard'
import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
import 'swiper/dist/css/swiper.css'
import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import i18n from './lang' // internationalization
import './icons' // icon
import './permission' // permission control
// import './utils/error-log' // error log
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import showHide from './utils/showHide'
import '@smallwei/avue/lib/index.css'
import './iconsFont/iconfont.css'
import '@/utils/global.js'
import Plugins from '@/utils/plugins.js'
import VueClipboard from 'vue-clipboard2'
import moment from 'moment'
import { vxeFormats } from '@/utils/filter'
import BaiduMap from 'vue-baidu-map'
import fileUploader from 'vue-simple-uploader'

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}
Vue.use(VueClipboard)
Vue.use(showHide)
Vue.use(EVue)
Vue.use(VXETable)
Vue.use(fileUploader)
Vue.use(VXETable)
Vue.use(fileUploader)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'Q47kDECgU9ROIGiWnyXldH0hL9IVhXxt'
})
// Vue.use(Antd)
// 去除eslint 警告
/*eslint no-extend-native: ["error", { "exceptions": ["Date"] }]*/
Date.prototype.format = function(format) {
  var o = {
    'M+': this.getMonth() + 1, // month
    'd+': this.getDate(), // day
    'h+': this.getHours(), // hour
    'm+': this.getMinutes(), // minute
    's+': this.getSeconds(), // second
    'q+': Math.floor((this.getMonth() + 3) / 3), // quarter
    'S': this.getMilliseconds() // millisecond
  }
  if (/(y+)/.test(format)) {
    format = format.replace(RegExp.$1,
      (this.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  for (var k in o) {
    if (new RegExp('(' + k + ')').test(format)) {
      format = format.replace(RegExp.$1,
        RegExp.$1.length === 1 ? o[k]
          : ('00' + o[k]).substr(('' + o[k]).length))
    }
  }
  return format
}
for (var key in Plugins) {
  Vue.prototype[`$${key}`] = Plugins[key]
}
// register global utility filters
// Object.keys(filters).forEach(key => {
//   Vue.filter(key, filters[key])
// })
Vue.prototype.Clipboard = Clipboard
Vue.config.productionTip = false
Vue.prototype.$moment = moment
// 表格-全局格式化内容（自定义全局的格式化处理函数）
vxeFormats()

const $vue = new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
window.vm = $vue
